﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tracy.DataModel;

namespace TracyGUI.UIComponent
{
    class TabPageResources : TabPageGeneric<Resource>
    {
        internal TabPageResources(string name, string text, ContextMenuStrip contextMenu) : base(name, text,contextMenu)
        {

        }

        protected override void InitColumns()
        {
            //TODO: load from settings
            AddColumn("Title");
            AddColumn("Source");
            AddColumn("FanSubGroup");
            AddColumn("Format");
            AddColumn("Resolution");
            AddColumn("Status");
            AddColumn("Created", ListViewColumnSorter.COLUMN_TYPE_DATE);
            _listViewItems.Columns["Title"].Width = 500;
        }

        protected override ListViewItem CreateListViewItem(Resource dataItem)
        {
            ListViewItem lvItem = new ListViewItem();
            lvItem.Name = dataItem.ID;
            lvItem.Tag = dataItem;
            lvItem.Text = dataItem.Title;

            AddSubListViewItem(lvItem, "Source", (dataItem.FeedSource == null) ? "" : dataItem.FeedSource.Name);
            AddSubListViewItem(lvItem, "FanSubGroup", (dataItem.FanSubGroups == null) ? "": FanSubGroup.GetCombinationName(dataItem.FanSubGroups));
            AddSubListViewItem(lvItem, "Format", (dataItem.Format == null) ? "" : dataItem.Format.Name);
            AddSubListViewItem(lvItem, "Resolution", (dataItem.Resolution == null) ? "" : dataItem.Resolution.Name);
            AddSubListViewItem(lvItem, "Status", dataItem.Status);
            AddSubListViewItem(lvItem, "Created", dataItem.Created);
            return lvItem;
        }

        protected override void UpdateListViewItem(ListViewItem lvItem, Resource dataItem)
        {
            lvItem.SubItems["Status"].Text = dataItem.Status;
        }
    }
}
